package com.wbu.estatemanagement.service.impl;

import com.wbu.estatemanagement.dao.BuildingMapper;
import com.wbu.estatemanagement.dao.CommunityMapper;
import com.wbu.estatemanagement.dao.HouseMapper;
import com.wbu.estatemanagement.dao.UserMapper;
import com.wbu.estatemanagement.domain.*;
import com.wbu.estatemanagement.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;
    @Autowired
    CommunityMapper communityMapper;
    @Autowired
    HouseMapper houseMapper;

    @Override
    public User findUser(Integer userId){
       User user=userMapper.selectByPrimaryKey(userId);

        //性别
        if(user.getSex().equals("0")){
            user.setSex("男");
        }else{
            user.setSex("女");
        }
        //租客类型
        if(user.getType().equals("0")){
            user.setType("房主");
        }else{
            user.setType("租客");
        }
        //所属社区
        Integer communityId = user.getCommunityId();
        Community community = communityMapper.selectByPrimaryKey(communityId);
        String communityname = community.getName();
        user.setCommunityName(communityname);
        //所属房产
        Integer houseId = user.getHouseId();
        House house = houseMapper.selectByPrimaryKey(houseId);
        String buildingname = house.getBuildingName();
        user.setBuildingName(buildingname);
        return user;
    }

    @Override
    public User findOne(User user) {
        User userOne = userMapper.selectOne(user);
        if (userOne==null){

        }
        return userOne;
    }

    @Override
    public Integer update(User user) {
        int i = userMapper.updateByPrimaryKey(user);
        return i;
    }


}
